﻿'Imports nsoftware.IPWorks.DataProvider
'Imports nsoftware.core
Imports System.Web.Configuration
Imports System.Net.Mail

Partial Class WebForm_Main
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If clsAuth.GetUser().UserType <> My.UserType.Employee Then
                Response.Redirect(clsAuth.GetDefaultUrl())
            End If

            Me.BindData()


            'Dim msg As New MailMessage()
            'msg.To.Add("buddhachaowei@gmail.com")
            'msg.From = New MailAddress("buddhawei@aa.com")
            'msg.Subject = "aaa"
            'msg.Body = "hhhhhhhhhh"

            'Dim smtp As New SmtpClient
            'smtp.Send(msg)

            'Response.Write(clsAuth.GetUser().UOrganizationID)
            Return

            'Dim sql As New MyAuthStringBuilder

            ''取得個人資訊
            'sql.Length = 0
            'sql.AppendFormat("select u.* ")
            'sql.AppendFormat("from [User] u ")

            'Response.Write(sql.ToString())

            'Dim dat As New clsData("SMTP")

            '發送郵件範例
            'http://blog.csdn.net/jfbao/archive/2004/12/14/216113.aspx

            'Using conn As New IPWorksConnection
            '    conn.ConnectionString = WebConfigurationManager.ConnectionStrings("SMTP").ConnectionString
            '    conn.Open()

            '    Dim sql As New MyStringBuilder

            '    sql.Length = 0
            '    sql.AppendFormat("insert into OUTBOX (sendto,messagefrom,subject,messagetext) ")
            '    'sql.AppendFormat("'{0}'", "buddhachaowei@gmail.com")
            '    'sql.AppendFormat(",'{0}'", "buddhachaowei@gmail.com")
            '    'sql.AppendFormat(",'{0}'", "bbbb")
            '    'sql.AppendFormat(",'{0}'", "aaaabbbbb")
            '    'sql.AppendFormat(")")

            '    Dim da As New IPWorksDataAdapter
            '    Dim dt As New Data.DataTable

            '    da.InsertCommand = New IPWorksCommand(sql.ToString(), conn)
            '    TryCast(da.InsertCommand.Parameters(0), Data.IDataParameter).Value = "buddhachaowei@gmail.com"
            '    TryCast(da.InsertCommand.Parameters(1), Data.IDataParameter).Value = "buddhachaowei@gmail.com"
            '    TryCast(da.InsertCommand.Parameters(2), Data.IDataParameter).Value = "ddd"
            '    TryCast(da.InsertCommand.Parameters(3), Data.IDataParameter).Value = "eeeeeeee"
            '    da.InsertCommand.ExecuteNonQuery()

            '    'sql.Length = 0
            '    'sql.AppendFormat("select * from default ")
            '    'da.SelectCommand = New IPWorksCommand(sql.ToString(), conn)
            '    'da.Fill(dt)

            '    'Response.Write(dt.Columns.Count)

            '    'For Each col As Data.DataColumn In dt.Columns
            '    '    Response.Write(col.ColumnName + "<br>")
            '    'Next
            'End Using




            'dat.AccData(sql)
        End If
    End Sub

    Protected Sub SearchBulletin1_Loaded(ByVal source As Object, ByVal e As System.EventArgs) Handles SearchBulletin1.Loaded
        Me.SearchBulletin1.BindGV(My.UserType.Employee)
    End Sub

    Protected Sub gvToDO_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvToDO.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            If DataBinder.Eval(e.Row.DataItem, "Col2").ToString() = "0" Then
                TryCast(e.Row.FindControl("mvCol2"), MultiView).SetActiveView(TryCast(e.Row.FindControl("vwText"), View))
            Else
                TryCast(e.Row.FindControl("mvCol2"), MultiView).SetActiveView(TryCast(e.Row.FindControl("vwUrl"), View))
            End If
        End If
    End Sub
End Class

Partial Class WebForm_Main
    Private Sub BindData()
        Me.BindGVToDo()
    End Sub

    Private Sub BindGVToDo()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.AppendFormat("select ")
        sql.AppendFormat("'[志工審核]' as col1 ")
        sql.AppendFormat(",'' as col2 ")
        sql.AppendFormat(",'' as url ")

        sql.AppendFormat("union all select ")
        sql.AppendFormat("'待初審志工人數:' as col1 ")
        sql.AppendFormat(",cast(count(*) as nvarchar(10)) as col2 ")
        sql.AppendFormat(",'~\WebForm\ApproveVolunteer.aspx' as url ")
        sql.AppendFormat("from (select distinct va.VolunteerID from VolunteerApplication va ")
        sql.AppendFormat("inner join WishOrganization wo on va.VolunteerID = wo.VolunteerID ")
        sql.AppendFormat("inner join UserOrganizationAuth oa on wo.OrganizationID = oa.OrganizationID ")
        sql.AppendFormat("where Status = '{0}'  ", My.FormStatus.Approving)
        sql.AppendFormat("and oa.UserID = '{0}') a ", clsAuth.GetUserID())

        sql.AppendFormat("union all select ")
        sql.AppendFormat("'待招募審核志工人數:' as col1 ")
        'sql.AppendFormat(",'' as col2 ")
        'sql.AppendFormat(",'' as url ")
        sql.AppendFormat(",cast(count(*) as nvarchar(10)) as col2 ")
        sql.AppendFormat(",'~\WebForm\ApproveVolunteer.aspx' as url ")
        sql.AppendFormat("from (select era.VolunteerID from EnlistRecordApplication era ")
        sql.AppendFormat("inner join EnlistHeader eh on era.EnlistID = eh.EnlistID ")
        '使用 sql function 會出現錯誤訊息: 找不到資料庫識別碼 102。 資料庫可能尚未啟動尚未或轉換中。
        'sql.AppendFormat("inner join UserOrganizationAuth oa on eh.UOrganizationID = dbo.GetUOrganizationID(oa.OrganizationID,oa.VOrganizationID) ")
        sql.AppendFormat("inner join UserOrganizationAuth oa on eh.UOrganizationID = cast(oa.OrganizationID as nvarchar(10)) + ',-1' ")
        sql.AppendFormat("where era.Status = '{0}'  ", My.FormStatus.Approving)
        sql.AppendFormat("and oa.UserID = '{0}') a ", clsAuth.GetUserID())

        sql.AppendFormat("union all select ")
        sql.AppendFormat("'待發放紀錄冊志工人數:' as col1 ")
        sql.AppendFormat(",cast(count(*) as nvarchar(10)) as col2 ")
        sql.AppendFormat(",'' as url ")
        sql.AppendFormat("from VolunteerDistinctView v ")
        sql.AppendFormat("where v.Active = '{0}' ", My.VolunteerStatus.Approving)

        sql.AppendFormat("union all select ")
        sql.AppendFormat("'[志工服務]' as col1 ")
        sql.AppendFormat(",'' as col2 ")
        sql.AppendFormat(",'' as url ")

        sql.AppendFormat("union all select ")
        sql.AppendFormat("'待處理髒亂點數量:' as col1 ")
        sql.AppendFormat(",cast(count(*) as nvarchar(10)) as col2 ")
        sql.AppendFormat(",'' as url ")
        sql.AppendFormat("from VolunteerDistinctView v ")
        sql.AppendFormat("where v.Active = '{0}' ", My.VolunteerStatus.Approving)

        sql.AppendFormat("union all select ")
        sql.AppendFormat("'待發放榮譽卡志工人數:' as col1 ")
        sql.AppendFormat(",cast(count(*) as nvarchar(10)) as col2 ")
        sql.AppendFormat(",'' as url ")
        sql.AppendFormat("from VolunteerDistinctView v ")
        sql.AppendFormat("where v.Active = '{0}' ", My.VolunteerStatus.Approving)

        Me.gvToDO.DataSource = dat.GetData(sql)
        Me.gvToDO.DataBind()

    End Sub
End Class